package team.knowers.firm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import team.knowers.firm.common.convention.result.Result;
import team.knowers.firm.common.convention.result.Results;
import team.knowers.firm.dao.entity.FlightDO;
import team.knowers.firm.dto.req.AddFlightReqDTO;
import team.knowers.firm.dto.req.PageFlightInfoReqDTO;
import team.knowers.firm.dto.resp.FlightInfoRespDTO;
import team.knowers.firm.service.FlightService;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class FlightController {
    private final FlightService flightService;

    @PostMapping("/api/firm/addFlight")
    Result<Boolean> addFlight(@RequestBody AddFlightReqDTO addFlightReqDTO) {
        return Results.success(flightService.addFlight(addFlightReqDTO));
    }
    @GetMapping("/api/firm/getAllFlightInfo")
    Result<IPage<FlightInfoRespDTO>>  getAllFlightInfo(PageFlightInfoReqDTO requestDTO) {
        return Results.success(flightService.getAllFlightInfo(requestDTO));
    }
    @GetMapping("/api/firm/getFlightInfo")
    Result<FlightInfoRespDTO> getFlightInfo(Integer id){
        return Results.success(flightService.getFlightInfo(id));
    }
    @PostMapping("/api/firm/deleteFlight")
    Result<Boolean> deleteFlight(Integer id) {
        return Results.success(flightService.deleteFlight(id));
    }
    @PostMapping("/api/firm/updateFlightInfo")
    Result<Boolean> updateFlightInfo(@RequestBody FlightDO req){
        return Results.success(flightService.updateFlight(req));
    }
    @GetMapping("/api/firm/getFlightInfoByFlightNo")
    Result<List<FlightInfoRespDTO>> getFlightInfoByFlightNo(String flightNo) {
        return Results.success(flightService.getFlightInfoByFlightNo(flightNo));
    }
}
